package org.apache.mina.example.lily.service;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

public class MyServer {

	NioSocketAcceptor acceptor;

	public MyServer(String host,int port) throws IOException {
		acceptor = new NioSocketAcceptor();
		acceptor.getSessionConfig().setTcpNoDelay(true);
		acceptor.getSessionConfig().setReuseAddress(true);
		acceptor.getSessionConfig().setKeepAlive(true);
		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new Codec(false)));
		acceptor.setHandler(new MyHandler());
		acceptor.bind(new InetSocketAddress(host,port));
	}
	
	public static void main(String[] args) {
		try {
			new MyServer("localhost",80);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
